package com.hongye.controller;

import java.util.List;

import com.hongye.app.model.ContentModel;
import com.jfinal.core.Controller;

public class ContentController extends Controller{
	public ContentController() {
		
	}
	
	/**
	 * ContentModel 列表
	 * @author lifuqiang
	 * 2017-3-29
	 */
	public void contentView(){
		List<ContentModel> list = ContentModel.getContentList();
		this.setAttr("contentlist", list);
		this.renderJsp("contentView.jsp");
	}
	
	/**
	 * content 详情
	 * @author lifuqiang
	 * 2017-3-29
	 */
	public void contentdetail(){
		String id = this.getPara("id");
		ContentModel content = ContentModel.getContentModel(id);
		this.setAttr("id", id);
		this.setAttr("content", content);
		this.renderJsp("contentDetail.jsp");
	}
	
	/**
	 * 添加 content
	 * @author lifuqiang
	 * 2017-3-29
	 */
	public void addContent(){
		String type = this.getPara("type");
		String title = this.getPara("title");
		String content = this.getPara("content");
		String summary = this.getPara("summary");
		String status = "1";//默认1启用
		boolean boo = ContentModel.addNewContent(type, title, content, summary, status);
		String rs="fal";
		if(boo){
			rs = "suc";
		}else{
			 rs="fal";
		}
		this.renderText(rs);
	}
	
	/**
	 * 更新 content
	 * @author lifuqiang
	 * 2017-3-29
	 */
	public void updateContent(){
		String id = this.getPara("id");
		String title = this.getPara("title");
		String content = this.getPara("content");
		String summary = this.getPara("summary");
		String status = this.getPara("status");
		String rs="fal";
		boolean boo = ContentModel.updateContent(id, title, content, summary, status);
		if(boo){
			rs = "suc";
		}else{
			 rs="fal";
		}
		this.renderText(rs);
	}
	
	/**
	 * 删除 content
	 * @author lifuqiang
	 * 2017-3-29
	 */
	public void deleteContent(){
		String id = this.getPara("id");
		boolean boo = ContentModel.deleteConten(id);
		String rs="fal";
		if(boo){
			rs = "suc";
		}else{
			 rs="fal";
		}
		this.renderText(rs);
	}
}
